package com.itcam.lease.web.app.service.impl;

import com.itcam.lease.model.entity.ViewAppointment;
import com.itcam.lease.web.app.mapper.ApartmentInfoMapper;
import com.itcam.lease.web.app.mapper.ViewAppointmentMapper;
import com.itcam.lease.web.app.service.ViewAppointmentService;
import com.itcam.lease.web.app.vo.apartment.ApartmentItemVo;
import com.itcam.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.itcam.lease.web.app.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;


    /**
     * 查询个人预约看房列表
     * @param userId
     * @return
     */
    @Override
    public List<AppointmentItemVo> listItemByUserId(Long userId) {
        return viewAppointmentMapper.listItemByUserId(userId);
    }

    /**
     * 根据ID查询预约详情信息
     * @param id 预约ID
     * @return 预约详情信息
     */
    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        // 根据ID查询预约信息
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);
        // 根据公寓ID查询公寓详情信息
        ApartmentItemVo apartmentItemVo = apartmentInfoMapper.selectApartmentItemVoById(viewAppointment.getApartmentId());

        // 创建预约详情信息对象
        AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();
        // 将预约信息复制到预约详情信息对象中
        BeanUtils.copyProperties(viewAppointment, appointmentDetailVo);
        // 将公寓详情信息设置到预约详情信息对象中
        appointmentDetailVo.setApartmentItemVo(apartmentItemVo);
        // 返回预约详情信息
        return appointmentDetailVo;
    }

}




